#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

#include<assert.h>



char* my_strncpy(char* dest, const char* src, size_t num)

{

	assert(dest && src);

	char* p = dest;

	while (num--)

	{

		*dest++ = *src++;

	}

	return p;

}

int main()

{

	char arr[] = "my name is Aha";

	char brr[20] = "aaaam";

	char* ret = my_strncpy(brr, arr, 4);

	printf("%s\n", brr);

	return 0;

}

char* my_strncat(char* dest, const char* src, size_t num)

{

	assert(dest && src);

	char* Dest = dest;

	while (*dest)

	{

		dest++;

	}

	while (num--)

	{

		*dest++ = *src++;

	}

	return Dest;

}

int main()

{

	char s1[20] = "my name is ";

	char s2[] = "zhang san";

	my_strncat(s1, s2, 7);

	printf("%s\n", s1);

	return 0;

}

void* my_memcpy(void* dest, const void* src, size_t num)

{

	assert(dest && src);

	void* Dest = dest;

	while (num--)

	{

		*((char*)dest)++ = *((char*)src)++;

	}

	return Dest;

}



int main()

{

	int n = 18;

	int N = 2;

	char s[20] = "hahahaha";

	char* S = "ooooo";

	my_memcpy(&n, &N, 4);

	my_memcpy(s, S, 3);

	printf("%d ", n);

	printf("%s\n ", s);

	return 0;

}

void* my_memmove(void* dest, const void* src, size_t num)

{

	assert(dest && src);

	void* Dest = dest;

	if (dest > src)

	{

		while (num--)

		{

			*((char*)dest + num) = *((char*)src + num);

		}

	}

	else

	{

		while (num--)

		{

			*((char*)dest)++ = *((char*)src)++;

		}

	}

	return Dest;

}



int main()

{

	char str[] = "memmove can be very useful......";

	my_memmove(str + 20, str + 15, 11);

	puts(str);

	return 0;

}